class Compilation {
    constructor(){

    }

    addEntry(entry){
        const asyncAueue = new AsyncQueue()
        asyncAueue.add(entry)
    }
} 


class AsyncQueue{
    constructor(){
        this.list = []
    }

    add(entry){
        this.list.push(entry)
        // 这里要使用bind指定this，不然this会执行执行调用者setImmediate
        setImmediate(this._ensureProcessing.bind(this))
    }

    _ensureProcessing(){
        for (let index = 0; index <  this.list.length; index++) {
            const entry = this.list[index];
            this._startProcessing(entry)
            
        }
    }

    _startProcessing(entry){
        console.log(entry)
    }
}
const compilation = new Compilation()
compilation.addEntry('app.js')
compilation.addEntry('search.js')